package com.itheima.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Evaluate;
import com.itheima.service.EvaluateService;
import org.springframework.web.bind.annotation.*;


/**
 * @author W.J.Y
 */
@RestController
@RequestMapping("evaluate")
public class EvaluateController {

    @Reference(version = "1.0.0")
    private EvaluateService evaluateService;

        
    /**
     * 分页查询方法
     * @param queryPageBean 分页参数实体类
     * @return  分页查询结果，总条数与当前页数据
     */
    @RequestMapping("findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult = evaluateService.findPage(
                queryPageBean.getCurrentPage(),
                queryPageBean.getPageSize(),
                queryPageBean.getQueryString());
        return pageResult;
    }

    @PostMapping("add")
    public Result add(@RequestBody Evaluate evaluate){

        return this.evaluateService.add(evaluate);

    }

    @GetMapping("delete/{id}")
    public Result delete(@PathVariable int id){
        //调用业务层删除方法
        evaluateService.delete(id);
        //返回操作结果
        return new Result(true, MessageConstant.DELETE_SUCCESS);
    }

    @RequestMapping("update")
    public Result update(@RequestBody Evaluate evaluate){
        //调用业务层修改方法
        evaluateService.update(evaluate);
        //返回操作结果
        return new Result(true, MessageConstant.UPDATE_SUCCESS);
    }
}
